
var app = getApp
Page({
  data: {
    // text:"这是一个页面"
    img:'',
    title:'',
    content:'',
    imgHdden: true
  },
  /**
   * 选择相册或者相机 配合上传图片接口用
   */
  listenerButtonChooseImage: function () {
    var that = this;
    that.setData({ imgHdden: false })
    wx.chooseImage({
      count: 1,
      //original原图，compressed压缩图
      sizeType: ['original'],
      //album来源相册 camera相机 
      sourceType: ['album', 'camera'],
      //成功时会回调
      
      success: function (res) {
        //重绘视图
        var tempFilePaths = res.tempFilePaths
        
        // wx.uploadFile({
        //   url: 'http://localhost/weicms/index.php?s=/addon/Cms/Cms/addList', //仅为示例，非真实的接口地址
        //   filePath: tempFilePaths[0],
        //   name: 'file',
        //   formData: {
        //     'user': 'test'
        //   },
        //   success: function (res) {
        //     console.log(res.data)
        //     var data = res.data
        //     //do something
        //     that.setData({ img: res.tempFilePaths })

        //   }
        // })
       that.setData({ img: res.tempFilePaths })
      }
    })
  },
  bindFormSubmit:function(e) {
    var that = this;
    var formData = e.detail.value;
    console.log(formData)
    console.log(e.detail.value.title)
    console.log(e.detail.value.content)
    wx.request({
      url: 'http://localhost/weicms/index.php?s=/addon/Cms/Cms/addList',
      data: formData,
      header: {
        'Content-Type': 'application/json'
      },
      success: function (res) {
        console.log(res.data)
      }
    })
  },
  bindFormReset: function () {
    console.log('form发生了reset事件');
  }  

})